package cos.android.tim.utils;

import cos.android.tim.element.Element;
import cos.android.tim.objects.Chain;
import cos.android.tim.objects.Rope;

public class Factory implements Cloneable {

	private Element element;
	private int posX;
	private int posY;

	private int number;

	public Factory() {
		super();
		this.element = null;
		this.number = 0;
	}

	public Factory(Element element, int number) {
		super();
		this.element = element;
		element.setFather(this);
		this.number = number;
	}

	public Element generateObject() {

		Element clone;
		if (number > 0) {
			clone = element.clone();
			number--;
			return clone;
		}
		return null;
	}

	public boolean isTouched(float touchX, float touchY) {

		if ((posX < touchX) && (posX + 100 > touchX)
				&& (posY < touchY )
				&& (posY + 70 > touchY)) {
			return true;
		} else {
			return false;
		}

	}

	public Element getElement() {
		return element;
	}

	public void setElement(Element element) {
		this.element = element;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public int getPosX() {
		return posX;
	}

	public void setPosX(int posX) {
		this.posX = posX;
	}

	public int getPosY() {
		return posY;
	}

	public void setPosY(int posY) {
		this.posY = posY;
	}

	public boolean isChain() {
		return (element instanceof Chain);
	}

	public boolean isRope() {
		return (element instanceof Rope);
	}

	@Override
	protected Factory clone() throws CloneNotSupportedException {
		Factory factory = new Factory();

		factory.setElement(element);
		factory.setNumber(number);
		factory.setPosX(posX);
		factory.setPosY(posY);
		return factory;
	}

}
